/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package core.api.a1;


import api.ResourceType;
import api.a1.AccumulateFunction;
import api.a1.definition.type.FactType;
import api.kieservices.Resource;
import core.api.a3.TypeResolver;
import core.impl.p1.Function;
import core.impl.p1.ImportDeclaration;
import core.impl.p1.RuleUnitRegistry;
import core.impl.p1.TraitRegistry;
import core.impl.p1.TypeDeclaration;
import core.impl.p1.WindowDeclaration;
import core.impl.p2.DialectRuntimeRegistry;
import core.impl.p2.RuleImpl;
import core.impl.p3.ClassFieldAccessorCache;
import core.impl.p3.ClassFieldAccessorStore;
import internal.api.a1.KnowledgePackage;
import internal.api.a1.ResourceTypePackage;
import api.kiecontainer.Process;

import java.io.Externalizable;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface InternalKnowledgePackage extends KnowledgePackage, Externalizable {

    void clear();
    void checkValidity();
    boolean isValid();

    void setNeedStreamMode();

    void resetErrors();
    void setError(String summary);


    Map<ResourceType, ResourceTypePackage> getResourceTypePackages();

    Map<String, String> getGlobals();
    Map<String, Process> getRuleFlows();
    Map<String, TypeDeclaration> getTypeDeclarations();
    Map<String, Function> getFunctions();
    Map<String, ImportDeclaration> getImports();
    Map<String, WindowDeclaration> getWindowDeclarations();
    Map<String, AccumulateFunction> getAccumulateFunctions();

    Set<String> getEntryPointIds();
    Set<String> getStaticImports();

    void addFunction(Function function);
    void addGlobal(String identifier, Class<?> clazz);
    void addEntryPointId(String id);
    void addWindowDeclaration(WindowDeclaration window);
    void addRule(RuleImpl rule);
    void addProcess(Process process);
    void addTypeDeclaration(TypeDeclaration typeDecl);
    void addFactTemplate(FactTemplate factTemplate);
    void addImport(ImportDeclaration importDecl);
    void addAccumulateFunction(String name, AccumulateFunction function);
    void addStaticImport(String functionImport);

    void removeFunction(String functionName);
    void removeRuleFlow(String id);
    void removeRule(RuleImpl rule);
    void removeGlobal(String identifier);

    boolean removeObjectsGeneratedFromResource(Resource resource);
    List<TypeDeclaration> removeTypesGeneratedFromResource(Resource resource);
    List<RuleImpl> removeRulesGeneratedFromResource(Resource resource);
    List<Function> removeFunctionsGeneratedFromResource(Resource resource);
    List<Process> removeProcessesGeneratedFromResource(Resource resource);

    DialectRuntimeRegistry getDialectRuntimeRegistry();
    void setDialectRuntimeRegistry(DialectRuntimeRegistry dialectRuntimeRegistry);

    RuleImpl getRule(String name);
    FactType getFactType(String typeName);
    TypeDeclaration getTypeDeclaration(Class<?> clazz);
    TypeDeclaration getTypeDeclaration(String type);
    FactTemplate getFactTemplate(String name);

    ClassLoader getPackageClassLoader();

    TypeResolver getTypeResolver();
    void setTypeResolver(TypeResolver typeResolver);

    RuleUnitRegistry getRuleUnitRegistry();

    ClassFieldAccessorStore getClassFieldAccessorStore();

    void setClassFieldAccessorCache(ClassFieldAccessorCache classFieldAccessorCache);

    InternalKnowledgePackage deepCloneIfAlreadyInUse(ClassLoader classLoader);

    boolean hasTraitRegistry();
    TraitRegistry getTraitRegistry();
}
